/**
 * 
 */
package pt.mleiria.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import pt.mleiria.bo.TextLoaderBO;
import pt.mleiria.vo.ContactsVO;

/**
 * @author root
 *
 */
public class ContactsController implements Controller {
	private TextLoaderBO textLoaderBO;
	/**
	 * @return the textLoaderBO
	 */
	public TextLoaderBO getTextLoaderBO() {
		return textLoaderBO;
	}

	/**
	 * @param textLoaderBO the textLoaderBO to set
	 */
	public void setTextLoaderBO(TextLoaderBO textLoaderBO) {
		this.textLoaderBO = textLoaderBO;
	}


	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse arg1) throws Exception {
		Map<String, Object> contactsMap = (Map<String, Object>)request.getSession().getAttribute("contactsMap");
		ContactsVO contacts = textLoaderBO.getContacts();
		contactsMap.put("contacts", contacts);
		request.getSession().setAttribute("contactsMap", contactsMap);
		return new ModelAndView("contacts");
	}

}
